package org.example;



import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.example.datasource.impl.DataLinkMedataDataSourceImpl;
import org.example.datasource.model.FieldMetadata;
import org.example.datasource.model.TableMetadata;
import org.example.dolph.DolphinschedulerClient;
import org.example.dolph.model.ProjectInfo;
import org.example.dolph.model.TaskDefine;
import org.example.dolph.model.TaskDetail;
import org.example.model.ColumnLineage;
import org.example.model.TableLineage;
import org.example.seatunnel.SeatunnelSinkWrapper;
import org.example.seatunnel.SeatunnelSourceWrapper;
import org.example.seatunnel.model.SinkResModel;
import org.example.seatunnel.model.SourceResModel;

import java.util.*;
import java.util.stream.Collectors;

public class SeatunnelParserv3 {


    public List<TableLineage> parse(String sql) {
        return null;
    }

    public static void main(String[] args) {


        String token = "d7516af061cd2af12e9f866f2a4199c9";	// dolphin scheduler token
        String dolphinAddress = "http://172.30.33.173:32777/dolphinscheduler";  // dolphin scheduler address
        // 元数据地址
        MetadataClient metadataClient = new MetadataClient("http://172.30.33.81:9000/api/openApi/lineage/pushLineages");
        String pyAddress = "http://172.30.33.81:8000/api/lineage";

        DataLinkMedataDataSourceImpl.address = "http://172.30.33.81:9000/api/openApi/table/metadata";

       // seatunnelParser.parse();



        DolphinschedulerClient dolphinschedulerClient = new DolphinschedulerClient(token, dolphinAddress);
        int count = 0;
        for (ProjectInfo projectInfo : dolphinschedulerClient.getProjects().getTotalList()) {

            for (TaskDefine taskDefine : dolphinschedulerClient.getTaskDefines(projectInfo.getCode()).getTotalList()) {

                if(taskDefine.getTaskType().equals("SEATUNNEL")){
                    TaskDetail taskDefine1 =  dolphinschedulerClient.getTaskDetail(projectInfo.getCode(),taskDefine.getTaskCode());
                    Config config =  ConfigFactory.parseString(taskDefine1.getSeaTaskParams().getRawScript());
String ss = "ckc2_gd_ryblxw\n" +
        "indicator_zhengshou_czcgzxmwcqk_copy1\n" +
        "ry_ryqk\n" +
        "st_dws_spf_jy_dt_mt_1\n" +
        "v_data_xsxx\n" +
        "view_2_fdcsc_kfjs_mt1\n" +
        "view_jianlizz";
                    String[] names = ss.split("\n");
                    for (String name : names) {
                        if (taskDefine1.getSeaTaskParams().getRawScript().contains(name)){
                            System.out.println(taskDefine.getTaskName());
                        }
                    }

                }
            }
        }



    }
}



//#Defining the runtime environment
//env {
//  # You can set flink configuration here
//    execution.parallelism = 4
//    job.mode = "BATCH"
//}
//source{
//    Jdbc {
//        url = "jdbc:sqlserver://172.30.36.154:1433;databaseName=SurveyAndDesign;encrypt=true;trustServerCertificate=true"
//        driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
//        user = "reader1"
//        password = "abc123!@#"
//        query ="select id,ryid,byyx,sxzy,rxsj,bysj,bz,status,create_time,zzcl from t_gd_ry_xxjl;"
//    }
//}
//
//sink {
//    jdbc {
//        url = "jdbc:mysql://172.30.36.144:9031/etl_ods?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8"
//        driver = "com.mysql.cj.jdbc.Driver"
//        user = "root"
//        password = ""
//        query = "insert into t_gd_ry_xxjl(id,ryid,byyx,sxzy,rxsj,bysj,bz,status,create_time,zzcl) VALUES ( ?,?,?,?,?,?,?,?,?,? )"
//    }
//}